local rolely_shenji = fk.CreateSkill {
    name = "rolely_shenji",
}
Fk:loadTranslationTable {
    ["rolely_shenji"] = "神戟",
    [":rolely_shenji"] = "当你使用【决斗】或【杀】时，你可以额外指定X个目标；当你使用【决斗】或【杀】造成伤害后，你摸X张牌(X为你的攻击距离，每名角色每回合限一次)。",

    ["#rolely_shenji-choose"] = "神戟：是否发动〖神戟〗，选择至多 %arg 名其他角色为目标。",
    ["#shenji-draw"] = "神戟：是否发动〖神戟〗，摸 %arg 张牌。",

    ["$rolely_shenji1"] = "方天画戟，振我神威！",
    ["$rolely_shenji2"] = "神兵在手，安敢妄言！",
    ["$rolely_shenji3"] = "化修罗，修战矛，斩三师，征九天！",
    ["$rolely_shenji4"] = "断轮回，笑忘川，召旧部，战黄泉！",
}
rolely_shenji:addEffect(fk.AfterCardTargetDeclared, {
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(rolely_shenji.name) and
            (data.card.trueName == "slash" or data.card.trueName == "duel") and
            table.find(data:getExtraTargets(), function(p)
                return player:inMyAttackRange(p)
            end)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(data:getExtraTargets(), function(p)
            return player:inMyAttackRange(p)
        end)
        local tos = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = player:getAttackRange(),
            prompt = "#rolely_shenji-choose:::" .. player:getAttackRange(),
            skill_name = rolely_shenji.name,
            cancelable = true,
        })
        if #tos > 0 then
            event:setCostData(self, { tos = tos })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        player:broadcastSkillInvoke(rolely_shenji.name, math.random(1, 2))
        player.room:notifySkillInvoked(player, rolely_shenji.name, "offensive")
        local targets = event:getCostData(self).tos
        for _, id in ipairs(targets) do
            player.room:doIndicate(player, { id })
            data:addTarget(id)
        end
    end,
})
rolely_shenji:addEffect(fk.Damage, {
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(rolely_shenji.name) and data.from == player and
            data.card and (data.card.trueName == "slash" or data.card.trueName == "duel") and
            data.to:getMark("shenji-turn") == 0
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,
            {
                skill_name = rolely_shenji.name,
                prompt = "#shenji-draw:::" .. player:getAttackRange()
            })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:broadcastSkillInvoke(rolely_shenji.name, math.random(3, 4))
        room:notifySkillInvoked(player, rolely_shenji.name, "drawcard")
        room:setPlayerMark(data.to, "shenji-turn", 1)
        player:drawCards(player:getAttackRange(), rolely_shenji.name)
    end,
})


return rolely_shenji
